package com.cwb.study.springbootstudy.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author ：chenwenbin
 * @date ：Created in 2019/08/08 11:06
 * @description：
 */
@Controller
public class LoginController {

   @PostMapping(value = "/user/login")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Map<String,Object> map, HttpSession session){
        if (!StringUtils.isEmpty(username) && "123".equals(password)){
            //登陆成功,防止表单重复提交,可以重定向到主页main
            session.setAttribute("loginUser",username);
            return "redirect:/main";
        }else {
            map.put("msg","用户名/密码错误");
            return "login";
        }

    }

}
